//
// Created by zerax on 2020/10/23.
//

#include "file_io.hh"
#include <vector>
#include <stdexcept>

using namespace std;

string FileIO::readText(string path) {
    auto* file = SDL_RWFromFile(path.c_str(), "rb");
    if (file == nullptr) {
        throw runtime_error("Failed to load " + path);
    }

    auto size = SDL_RWsize(file);
    vector<char> buffer(size + 1);
    SDL_RWread(file, buffer.data(), size + 1, 1);
    SDL_RWclose(file);
    return string(buffer.begin(), buffer.end());
}